/**

* <p>Title: UserController.java</p>

* <p>Description: </p>

* <p>Copyright: Copyright (c) 2021</p>

* <p>Company: www.chinasofti.com</p>

* @author knowno

* @date 2021年3月11日

* @version 1.0

*/
package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.dao.GoodsMapper;
import com.etc.entity.Goods;
import com.etc.zmall.service.GoodsService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.ApiParam;

/**
 * 
 * <p>
 * Title: UserController
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * @author knowno
 * 
 * @date 2021年3月11日
 * 
 */
@Controller
public class FGoodsController {

	@Autowired
	private GoodsService goodsService;

	@GetMapping(value = "api/front/listGoods")
	public String listGoods(
			@ApiParam(name = "keywords", required = false, value = "商品查询关键字") @RequestParam(value = "keywords", required = false, defaultValue = "") String keywords,
			@RequestParam(value = "page", required = false, defaultValue = "1") int page,
			@RequestParam(value = "limit", required = false, defaultValue = "10") int limit, Model model) {

		// 调用业务层方法实现分页查询
		PageInfo<Goods> pageinfo = goodsService.showGoodsDetail(page, limit, keywords);

		model.addAttribute("pageinfo", pageinfo);
		model.addAttribute("keywords", keywords);
		return "forward:/efront/UserIndex.jsp";
	}

	@GetMapping(value = "api/front/listGoods/{goodsid}")
	@ResponseBody
	public Goods listGoodsById(@PathVariable("goodsid") int goodsid) {
		return goodsService.getGoodsById(goodsid);
	}

}
